<?php
namespace Admin\Controller;
use Think\Controller;
class UserController extends Controller {
	public function __construct(){
		parent::__construct();
		if(!$_SESSION['admin_is_login']){
			$this->redirect('admin/Auth/login');
		}
	}
    public function index(){
        //用户列表的分页
        $user_model = M('user_admin');
        $count=$user_model->count();
        $Page=new \Org\Util\Page($count,5);
        $show=$Page->show();
    	$user=$user_model->select();
    	$this->assign('users',$user);
        $this->assign('page',$show);
        $this->display();
    }
    public function del($id){
    	M('user_admin')->where('id='.$id)->delete();
    	$this->redirect('admin/User/index');
    }
    //禁用启用的三目运算符做法
    // public function status($id){
    //     $user=M('user_admin')->where('id='.$id)->find();
    //     $status=$user['status'];
    //     if($status){
    //         $status=0;
    //     }else{
    //         $status=-1;
    //     }
    //     M('user_admin')->where('id='.$id)->save(array(
    //         'status'=>$status
    //     ));
    //     $this->redirect('admin/User/index');
    // }
    public function ban($id){
        M('user_admin')->where('id='.$id)->save(array(
            'status'=>-1
        ));
        $this->redirect('admin/User/index');
    }
    public function enable($id){
          M('user_admin')->where('id='.$id)->save(array(
            'status'=>0
        ));
        $this->redirect('admin/User/index');
    }
}